﻿namespace HuaweiCloud.Dotnet.Samples.Cache4Redis
{
    public static class ProductStore
    {
        /// <summary>
        /// 默认 初始数据 直接存放在内存中
        /// </summary>
        private static List<Product> _store = new List<Product>()
        {
            new Product(1, "Huawei Watch GT", 100),
            new Product(2, "Huawei Watch Pro", 50)
        };
        /// <summary>
        /// 获取全部数据 
        /// </summary>
        /// <returns></returns>
        public static Task<List<Product>> GetAllAsync()
        {
            var tcs = new TaskCompletionSource<List<Product>>();
            // 模拟远程异步获取数据
            Task.Run(async () =>
            {
                var temp = new List<Product>();
                for (int i = 0; i < _store.Count; i++)
                {
                    await Task.Delay(100);
                    temp.Add(_store[i]);
                }
                tcs.TrySetResult(temp);
            });
            return tcs.Task;
        }
    }
}
